<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\facade\Builder;

class Release extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Release';

    //关联模型
    protected array $hasOne = ['user', 'qUser'];


    public function index(): string
    {
        //构建表格数据
        return Builder::Table()
            ->addColumn(['type' => 'checkbox', 'title' => '全选', 'fixed' => 'left'])
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'referee', 'title' => '推荐人', 'templet' => '<div>{{d.user.code}}</div>'])
            ->addColumn(['field' => 'q_referee', 'title' => '被推荐人', 'templet' => '<div>{{d.qUser.code}}</div>'])
            ->addColumn(['field' => 'type', 'title' => '类型', 'templet' => '<div>{{d.type==1?"每日释放":"每月释放"}}</div>'])
            ->addColumn(['field' => 'once', 'title' => '每次释放'])
            ->addColumn(['field' => 'already', 'title' => '已释放'])
            ->addColumn(['field' => 'capping', 'title' => '封顶'])
            ->addColumn(['field' => 'is_capping', 'title' => '是否封顶', 'templet' => '<div>{{d.is_capping==1?"已封顶":"未封顶"}}</div>'])
            ->addColumn(['field' => 'create_time', 'title' => '创建时间'])
            ->addSearch([
                ['uid', '推荐人编号/昵称/手机号', 'input', '', '\app\common\model\User', 'code|nickname|mobile,id'],
            ])
            ->fetch();
    }


}
